package Client;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LineReader implements Runnable {
	private Client client;
	private CommandHandler commandHandler;
	private BufferedReader br;

	public LineReader(Client client) {
		this.client = client;
		br = new BufferedReader(new InputStreamReader(System.in));
		commandHandler = client.getCommandHandler();
	}

	public void run() {
		try {
			while (true) {
				String inputLine = "";
				System.out.print("enter your passnumber: ");
				String login = "login " + br.readLine();
				System.out.print("Enter your pincode: ");
				login = login + " " + br.readLine();
				commandHandler.handleInput(login);
				client.setWaiting(true);
				while (client.hasLoggedIn() || client.getWaiting()) {
					inputLine = br.readLine();
					if (inputLine != null && !inputLine.equals("")) {
						commandHandler.handleInput(inputLine);
					}
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
